package com.beehoo.dcportal.admin.action;

import java.util.List;

import com.beehoo.dcportal.admin.service.RelatedLinkService;
import com.beehoo.dcportal.common.Constant;
import com.beehoo.dcportal.common.base.BaseAction;
import com.beehoo.dcportal.common.base.BaseException;
import com.beehoo.dcportal.model.RelatedLinkBean;

public class RelatedLinkAction extends BaseAction {

	private static final long serialVersionUID = 1003649667976472203L;
	private RelatedLinkService relatedLinkService;
	private List<RelatedLinkBean> resultList;
	private RelatedLinkBean relatedLinkBean;
	private String linkId;

	public RelatedLinkBean getRelatedLinkBean() {
		return relatedLinkBean;
	}

	public void setRelatedLinkBean(RelatedLinkBean relatedLinkBean) {
		this.relatedLinkBean = relatedLinkBean;
	}

	public List<RelatedLinkBean> getResultList() {
		return resultList;
	}

	public void setResultList(List<RelatedLinkBean> resultList) {
		this.resultList = resultList;
	}

	public String getLinkId() {
		return linkId;
	}

	public void setLinkId(String linkId) {
		this.linkId = linkId;
	}

	public void setRelatedLinkService(RelatedLinkService relatedLinkService) {
		this.relatedLinkService = relatedLinkService;
	}

	public String list(){
		String streetId = (String) getSession().get(Constant.SESSION_STREET_ID);
		try {
			resultList = relatedLinkService.queryRelatedLink(streetId, null);
			relatedLinkBean = null;
		} catch (BaseException e) {
			setMessage(super.getText(e.getMessage()));
		}
		return SUCCESS;
	}
	
	public String del(){
		try {
			relatedLinkService.deleteRelatedLink(linkId);
		} catch (BaseException e) {
			setMessage(super.getText(e.getMessage()));
		}
		return list();
	}
	
	public String create(){
		String streetId = (String) getSession().get(Constant.SESSION_STREET_ID);
		if(relatedLinkBean != null){
			relatedLinkBean.setStreetId(streetId);
		}
		try {
			relatedLinkService.createRelatedLink(relatedLinkBean);
		} catch (BaseException e) {
			setMessage(super.getText(e.getMessage()));
		}
		return list();
	}
}
